package pam.security;

import pam.core.XMLObject;

/**
 * 权限类
 */
public class Permission implements XMLObject {

	/** 权限名称 */
	private String title;

	/** 权限标识 */
	private long id;

	public Permission() {
	}

	public Permission(long id, String title) {
		setId(id);
		setTitle(title);
	}

	public String getTitle() {
		return title;
	}

	public long getId() {
		return id;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setId(long id) {
		this.id = id;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Permission other = (Permission) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public String toXML() {
		StringBuffer sb = new StringBuffer();
		sb.append("<Permission>");

		sb.append("<ID>");
		sb.append(getId());
		sb.append("</ID>");

		sb.append("<Title>");
		sb.append(getTitle() == null ? "" : getTitle());
		sb.append("</Title>");

		sb.append("</Permission>");

		return sb.toString();
	}

}
